package com.springboot01.service.impl;

import com.springboot01.dao.UserDAO;
import com.springboot01.entity.User;
import com.springboot01.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author MagicMushroom
 * @date 2021/6/29
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserDAO userDAO;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public List<User> findAll() {
        return userDAO.findAll();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertOne(User user) {
        userDAO.InsertOne(user);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public User findOne(Integer id) {
        return userDAO.findOne(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(User user) {
        userDAO.update(user);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteOne(Integer id) {
        userDAO.deleteOne(id);
    }
}
